home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Screenblankers / GBlanker / GSource / GadTools / Garshneblanker.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  7KB  |  258 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Michael D. Bayne
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include <pragmas/exec_pragmas.h>
  26. #include <pragmas/intuition_pragmas.h>
  27. #include <pragmas/gadtools_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/utility_pragmas.h>
  30.  
  31. #include "Garshneblanker.h"
  32.  
  33. struct Screen         *Scr = NULL;
  34. UBYTE                 *PubScreenName = NULL;
  35. APTR                   VisualInfo = NULL;
  36. struct Window         *BlankerWnd = NULL;
  37. struct Gadget         *BlankerGList = NULL;
  38. struct IntuiMessage    BlankerMsg;
  39. struct Gadget         *BlankerGadgets[6];
  40. UWORD                  BlankerLeft = 0;
  41. UWORD                  BlankerTop = 16;
  42. UWORD                  BlankerWidth = 214;
  43. UWORD                  BlankerHeight = 99;
  44. UBYTE                 *BlankerWdt = (UBYTE *)"Garshneblanker";
  45. struct TextAttr       *Font, Attr;
  46. UWORD                  FontX, FontY;
  47. UWORD                  OffX, OffY;
  48. struct TextFont       *BlankerFont = NULL;
  49.  
  50. UWORD BlankerGTypes[] = {
  51.     BUTTON_KIND,
  52.     BUTTON_KIND,
  53.     LISTVIEW_KIND,
  54.     BUTTON_KIND,
  55.     BUTTON_KIND,
  56.     BUTTON_KIND
  57. };
  58.  
  59. struct NewGadget BlankerNGad[] = {
  60.     159, 61, 51, 15, (UBYTE *)"_Hide", NULL, GD_BT_HIDE, PLACETEXT_IN, NULL, (APTR)BT_HIDEClicked,
  61.     159, 80, 51, 15, (UBYTE *)"_Quit", NULL, GD_BT_QUIT, PLACETEXT_IN, NULL, (APTR)BT_QUITClicked,
  62.     4, 4, 151, 90, NULL, NULL, GD_LV_BLANKERS, 0, NULL, (APTR)LV_BLANKERSClicked,
  63.     159, 4, 51, 15, (UBYTE *)"_Prefs", NULL, GD_BT_PREFS, PLACETEXT_IN, NULL, (APTR)BT_PREFSClicked,
  64.     159, 23, 51, 15, (UBYTE *)"_Info", NULL, GD_BT_INFO, PLACETEXT_IN, NULL, (APTR)BT_INFOClicked,
  65.     159, 42, 51, 15, (UBYTE *)"_Toggle", NULL, GD_BT_TOGGLE, PLACETEXT_IN, NULL, (APTR)BT_TOGGLEClicked
  66. };
  67.  
  68. extern struct Hook RenderHook;
  69.  
  70. ULONG BlankerGTags[] = {
  71.     (GT_Underscore), '_', (TAG_DONE),
  72.     (GT_Underscore), '_', (TAG_DONE),
  73.     (GTLV_ShowSelected), NULL, (GTLV_CallBack), &RenderHook, (TAG_DONE),
  74.     (GT_Underscore), '_', (TAG_DONE),
  75.     (GT_Underscore), '_', (TAG_DONE),
  76.     (GT_Underscore), '_', (TAG_DONE)
  77. };
  78.  
  79. static UWORD ComputeX( UWORD value )
  80. {
  81.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  82. }
  83.  
  84. static UWORD ComputeY( UWORD value )
  85. {
  86.     return(( UWORD )((( FontY * value ) + 4 ) / 9 ));
  87. }
  88.  
  89. static void ComputeFont( UWORD width, UWORD height )
  90. {
  91.     Forbid();
  92.     Font = &Attr;
  93.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  94.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  95.     FontX = GfxBase->DefaultFont->tf_XSize;
  96.     Permit();
  97.  
  98.     OffX = Scr->WBorLeft;
  99.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  100.  
  101.     if ( width && height ) {
  102.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  103.             goto UseTopaz;
  104.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  105.             goto UseTopaz;
  106.     }
  107.     return;
  108.  
  109. UseTopaz:
  110.     Font->ta_Name = (STRPTR)"topaz.font";
  111.     FontX = FontY = Font->ta_YSize = 8;
  112. }
  113.  
  114. int SetupScreen( void )
  115. {
  116.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  117.         return( 1L );
  118.  
  119.     ComputeFont( 0, 0 );
  120.  
  121.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  122.         return( 2L );
  123.  
  124.     return( 0L );
  125. }
  126.  
  127. void CloseDownScreen( void )
  128. {
  129.     if ( VisualInfo ) {
  130.         FreeVisualInfo( VisualInfo );
  131.         VisualInfo = NULL;
  132.     }
  133.  
  134.     if ( Scr        ) {
  135.         UnlockPubScreen( NULL, Scr );
  136.         Scr = NULL;
  137.     }
  138. }
  139.  
  140. int HandleBlankerIDCMP( void )
  141. {
  142.     struct IntuiMessage    *m;
  143.     int            (*func)();
  144.     BOOL            running = TRUE;
  145.  
  146.     while( m = GT_GetIMsg( BlankerWnd->UserPort )) {
  147.  
  148.         CopyMem(( char * )m, ( char * )&BlankerMsg, (long)sizeof( struct IntuiMessage ));
  149.  
  150.         GT_ReplyIMsg( m );
  151.  
  152.         switch ( BlankerMsg.Class ) {
  153.  
  154.             case    IDCMP_REFRESHWINDOW:
  155.                 GT_BeginRefresh( BlankerWnd );
  156.                 GT_EndRefresh( BlankerWnd, TRUE );
  157.                 break;
  158.  
  159.             case    IDCMP_CLOSEWINDOW:
  160.                 running = BlankerCloseWindow();
  161.                 break;
  162.  
  163.             case    IDCMP_VANILLAKEY:
  164.                 running = BlankerVanillaKey();
  165.                 break;
  166.  
  167.             case    IDCMP_GADGETUP:
  168.             case    IDCMP_GADGETDOWN:
  169.                 func = ( void * )(( struct Gadget * )BlankerMsg.IAddress )->UserData;
  170.                 running = func();
  171.                 break;
  172.  
  173.             case    IDCMP_MENUPICK:
  174.                 break;
  175.         }
  176.     }
  177.     return( running );
  178. }
  179.  
  180. int OpenBlankerWindow( void )
  181. {
  182.     struct NewGadget    ng;
  183.     struct Gadget    *g;
  184.     UWORD        lc, tc;
  185.     UWORD        wleft = BlankerLeft, wtop = BlankerTop, ww, wh;
  186.  
  187.     ComputeFont( BlankerWidth, BlankerHeight );
  188.  
  189.     ww = ComputeX( BlankerWidth );
  190.     wh = ComputeY( BlankerHeight );
  191.  
  192.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  193.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  194.  
  195.     if ( ! ( BlankerFont = OpenDiskFont( Font )))
  196.         return( 5L );
  197.  
  198.     if ( ! ( g = CreateContext( &BlankerGList )))
  199.         return( 1L );
  200.  
  201.     for( lc = 0, tc = 0; lc < Blanker_CNT; lc++ ) {
  202.  
  203.         CopyMem((char * )&BlankerNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  204.  
  205.         ng.ng_VisualInfo = VisualInfo;
  206.         ng.ng_TextAttr   = Font;
  207.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  208.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  209.         ng.ng_Width      = ComputeX( ng.ng_Width );
  210.         ng.ng_Height     = ComputeY( ng.ng_Height);
  211.  
  212.         BlankerGadgets[ lc ] = g = CreateGadgetA((ULONG)BlankerGTypes[ lc ], g, &ng, ( struct TagItem * )&BlankerGTags[ tc ] );
  213.  
  214.         while( BlankerGTags[ tc ] ) tc += 2;
  215.         tc++;
  216.  
  217.         if ( NOT g )
  218.             return( 2L );
  219.     }
  220.  
  221.     if ( ! ( BlankerWnd = OpenWindowTags( NULL,
  222.                 WA_Left,    wleft,
  223.                 WA_Top,        wtop,
  224.                 WA_Width,    ww + OffX + Scr->WBorRight,
  225.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  226.                 WA_IDCMP,    BUTTONIDCMP|LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  227.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SIZEBBOTTOM|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  228.                 WA_Gadgets,    BlankerGList,
  229.                 WA_Title,    BlankerWdt,
  230.                 WA_ScreenTitle,    "Garshneblanker",
  231.                 WA_PubScreen,    Scr,
  232.                 TAG_DONE )))
  233.     return( 4L );
  234.  
  235.     GT_RefreshWindow( BlankerWnd, NULL );
  236.  
  237.     return( 0L );
  238. }
  239.  
  240. void CloseBlankerWindow( void )
  241. {
  242.     if ( BlankerWnd        ) {
  243.         CloseWindow( BlankerWnd );
  244.         BlankerWnd = NULL;
  245.     }
  246.  
  247.     if ( BlankerGList      ) {
  248.         FreeGadgets( BlankerGList );
  249.         BlankerGList = NULL;
  250.     }
  251.  
  252.     if ( BlankerFont ) {
  253.         CloseFont( BlankerFont );
  254.         BlankerFont = NULL;
  255.     }
  256. }
  257.  
  258.